<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>参数传递</title>
</head>
<body>
    <p>
        <input type="text" id="username">
    </p>

    <p>
        <input type="text" id="age">
    </p>

    <p>
        <input type="button" id="btn" value="提交">
    </p>

    <script type="text/javascript">
	    var usrname = document.getElementById('username')
	    var usrage = document.getElementById('age')
        var btn = document.getElementById('btn');

        btn.onclick = function () {
        	var usr = usrname.value;
        	var age = usrage.value;
            var xhr = new XMLHttpRequest()
            news = 'username=' + usr +'&age=' + age
            // get 请求
            // xhr.open('get','http://localhost:3000/third?'+ news)
            // xhr.send()
            // post 请求
            xhr.open('post','http://localhost:3000/third')
            xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
            xhr.send(news)


            xhr.onload = function () {
	        	console.log(xhr.responseText)
            }
        }
    </script>
</body>
</html>